package cn.edu.mju.property.web.controller;

import cn.edu.mju.property.entity.Notice;
import cn.edu.mju.property.entity.PageBean;
import cn.edu.mju.property.entity.Unit;
import cn.edu.mju.property.service.NoticeService;
import cn.edu.mju.property.service.UnitService;
import cn.edu.mju.property.service.impl.NoticeServiceImpl;
import cn.edu.mju.property.service.impl.UnitServiceImpl;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/FindUnitByPage")
public class FindUnitByPage extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        response.setContentType("application/json; charset=UTF-8");
        response.setDateHeader("expries", -1);
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");

        String currentPage = request.getParameter("page"); //当前页码
        String rows =request.getParameter("limit"); //每页显示条数


        UnitService service = new UnitServiceImpl();
        PageBean<Unit> pb = service.findUnitByPage(currentPage,rows);


        JSONObject result = new JSONObject();
        result.put("code","0");
        result.put("msg",null);
        result.put("count",pb.getTotalCount());
        result.put("data", pb.getList());

        response.getWriter().write(String.valueOf(result));

    }
}
